package com.oto.web.resource;

import java.util.List;
import java.util.Set;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.oto.Constants;
import com.oto.model.FlowDO;
import com.oto.util.JAXBUtils;

/**
 * @author xueqiang.mi
 * @since 2011-1-15
 */
@Path("/search")
@Component
@Scope(BeanDefinition.SCOPE_SINGLETON)
public class SearchResource extends BaseResource {

	@GET
	@Produces("application/xml")
	public String search(@QueryParam(value = "key") String key) {
		messageService.store("processing keywords:" + key);

		Set<String> keys = searchService.parse(key);
		List<FlowDO> flows = searchService.search(keys, Constants.MED_SIZE);
		return JAXBUtils.writeMessage(flows);
	}
}
